// JavaScript Document
var info;
var pt;
$(function(){
	moodIndexInfo();
	tagTool();
	$("#myli").mouseover(function(){
		$("#myspan").css("display","block");
		$("#current_userInfo").css("display","block");
	});
	$("#myli").mouseout(function(){
		$("#myspan").css("display","none");
		$("#current_userInfo").css("display","none");
	});
});

/*根据标签查*/
function seeMoodByTag(val){
	$.post("../json/moodsAction_moodByTag",{"mood.mtag":val},function(data){
		if(data.total > 0) {
			pt = new PageTool(10, data.total);
			$("#tot_page").text(pt.totalSize);
			info = data;
			showInfo(data,pt.begin(),pt.end());
		} else {
			var p='<li><p style="font-size:12px;color:#333;text-align:center;';
			p+='width:100%;height:50px;line-height:50px;">暂无数据</p></li>';
			$(".left_moods_content ul").html(p);
		}
	},"json");
}

/*标签工具*/
function tagTool() {
	var lis= $("#right_label_type ul li");
	var tag = '';
	$.each(lis,function(i){
		$(lis[i]).click(function(){
			tag=$(lis[i]).children("a").text();
			$.post("../json/moodsAction_moodByTag",{"mood.mtag":tag},function(data){
				if(data.total > 0) {
					pt = new PageTool(10, data.total);
					$("#tot_page").text(pt.totalSize);
					info = data;
					showInfo(data,pt.begin(),pt.end());
				} else {
					var p='<li><p style="font-size:12px;color:#333;text-align:center;';
					p+='width:100%;height:50px;line-height:50px;">暂无数据</p></li>';
					$(".left_moods_content ul").html(p);
				}
			},"json");
		});
	});
}

function showOneMood(val) {
	$.post("../json/moodsAction_seeOneMood",{"mood.mid":val},function(data){
		if(data.result > 0) {
			location.href="commentMood.jsp";
		}else{
			alert("系统错误!");
		}
	},"json");
}

function userInfo(val) {
	
}

function myMoodData() {
	if(w_uid!="") {
		$.post("../json/moodsAction_myMood",function(data) {
			if(data.total != 0){
				pt=new PageTool(10,data.total);
				$("#tot_page").text(pt.totalSize);
				info=data;
				showInfo(info,pt.begin(),pt.end());
			}else{
				var p='<li><p style="font-size:12px;color:#333;text-align:center;';
					p+='width:100%;height:50px;line-height:50px;">暂无数据</p></li>';
				$(".left_moods_content ul").html(p);
			}
		},"json");
	} else {
		alert("请登录!");
		location.href="../login/login.html"
	}
}

function moodIndexInfo() {
	$.post("../json/moodsAction_moodData",function(data) {
		if(data.total != 0){
			pt=new PageTool(10,data.total);
			$("#tot_page").text(pt.totalSize);
			info=data;
			showInfo(info,pt.begin(),pt.end());
		}else{
			var p='<li><p style="font-size:12px;color:#333;text-align:center;';
				p+='width:100%;height:50px;line-height:50px;">暂无数据</p></li>';
			$(".left_moods_content ul").html(p);
		}
	},"json");
}

//获取时间的方法
function getTime(){
	var date = new Date();
	var year = date.getFullYear();
	var month = date.getMonth()+1;
	var ri = date.getDate();
	var hour = date.getHours();
	var min = date.getMinutes();
	if(month<10){
		month="0"+month;
	}
	if(ri<10){
		ri="0"+ri;
	}
	var d = year+"-"+month+"-"+ri+" "+hour+":"+min;
	return d;
}

//显示评论
function showInfo(data,begin,end){
	var str="";
	$(document).scrollTop(0);
	$("#cur_page").text(pt.pageNo);
	$.each(data.rows,function(index,item){
		if(index>=begin && index<end){
			str+='<li class="moods_info"><div class="moods_info_header"><a href="#"><img src="images/logo.jpg" alt="用户头像"/></a></div>';
			str+='<div class="moods_info_content"><input type="hidden" name="mid" class="mid" value="'+item.mid+'" />';
			str+='<a class="mtitle" href="javascript:showOneMood(\''+item.mid+'\')">';
			str+=item.mname+'</a><br /><br />'+item.mcontent+'<br /><br /><span>#&nbsp;</span><a ';
			str+='href="javascript:seeMoodByTag(\''+item.mtag+'\')" class="comment_label">'+item.mtag+'</a><p>来自&nbsp;&nbsp;';
			if(item.mstatus == "匿名"){
				str+='<span>'+item.mstatus+'</span>';
			}else{	
				str+='<a href="javascript:userInfo(\''+item.mid+'\')">'+item.mstatus+'</a>';
			}
			str+='&nbsp;&nbsp;发表于&nbsp;'+item.mtime+'</p></div></li>';
		}
	});
	$(".left_moods_content ul").html(str);
}


//分页工具
function pageTool(val){
	if(val==0){
		pt.ind();
	}else if(val==-1){
		pt.pre();
	}else if(val==1){
		pt.nex();
	}else{
		pt.las();
	}
	showInfo(info,pt.begin(),pt.end());
}

